package org.zoomdev.zoom.validator.impl;


import org.zoomdev.zoom.validator.Validator;
import org.zoomdev.zoom.validator.annotations.Max;

public class MaxValidator implements Validator {

    private final long max;

    private final String message;

    public MaxValidator(Max range) {
        this.max = range.value();
        this.message = range.message();
    }

    @Override
    public boolean isValid(Object value) {
        if (!(value instanceof Number)) return true;
        long num = ((Number) value).longValue();
        return num <= max;
    }

    @Override
    public String getMessage() {
        return message;
    }
}